package com.un.ebs.inventory.mapper;

import com.baomidou.mybatisplus.annotation.SqlParser;
import com.un.ebs.inventory.domain.EntRelation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.un.ebs.inventory.domain.EntRelationExt;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author liubo
 * @since 2020-05-28
 */
@Component
public interface EntRelationMapper extends BaseMapper<EntRelation> {

    @SqlParser(filter = true)
    @Select("select isnull(max(code),0)+1 from tb_ent_relation where relation_type=#{type} and ent_id=#{entId}")
    int selectMax(@Param("type") int type,@Param("entId") String entId);

    @SqlParser(filter = true)
    @Select("SELECT [dbo].[fun_getNoteTypeID](#{type},#{tenantId})")
    String queryNoteTypeId(@Param("type") int type, @Param("tenantId") String tenantId);

    @SqlParser(filter = true)
    @Select("EXECUTE [dbo].[sp_test] #{type}")
    void execSp(@Param("type") int type);

    @SqlParser(filter = true)
    @Select("select * from tb_ent_relation where ent_id=#{entId} and open_api_user_id=#{openApiUserId}")
    EntRelation queryEntRelationId(String entId, String openApiUserId);

    @SqlParser(filter = true)
    @Select("select * from tb_ent_relation where ent_id=#{entId} and relation_type=#{type}")
    EntRelation queryEntRelationByEntId(@Param("entId") String entId,@Param("type") int type);

    @SqlParser(filter = true)
    @Select("select count(id) from tb_ent_relation where ent_id=#{entId} and open_api_user_id=#{openApiUserId}")
    int queryEntRelationCount(String entId, String openApiUserId);

    @SqlParser(filter = true)
    @Select("select name from v_ent_relation_ext where id = #{id}")
    String queryEntNameByEntRelationId(String id);
}
